using System;
using System.Collections;
using System.IO;

namespace System.Windows.Media.DirectShow.Vorbis
{

    public class Mode
    {

        private bool blockFlag;
        private int windowType, transformType, mapping;

        public Mode(IBitStream source, SetupHeader header)
        {
            blockFlag = source.ReadBit();
            windowType = source.ReadInt32(16);
            transformType = source.ReadInt32(16);
            mapping = source.ReadInt32(8);

            if (windowType != 0)
            {
                throw new VorbisFormatException("Window type = " + windowType + ", != 0");
            }

            if (transformType != 0)
            {
                throw new VorbisFormatException("Transform type = " + transformType + ", != 0");
            }

            if (mapping > header.Mappings.Length)
            {
                throw new VorbisFormatException("Mode mapping number is higher than total number of mappings.");
            }
        }

        public bool BlockFlag
        {
            get
            {
                return blockFlag;
            }
        }

        public int WindowType
        {
            get
            {
                return windowType;
            }
        }

        public int TransformType
        {
            get
            {
                return transformType;
            }
        }

        public int Mapping
        {
            get
            {
                return mapping;
            }
        }
    }

}